package com.wd.amodel.vm;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;

import com.wd.amodel.vm.fetcher.ListImgDataFetcher;
import com.wd.amodel.vm.listener.ILoginImageListListener;
import com.wd.base.service.ServiceFactory;
import com.wd.base.util.Logger;
import com.wd.common.userservice.IMemberCommonService;
import com.wd.common.userservice.bean.TestBean;

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V2.0.0, 2021/4/23]
 * @since V2.0.0
 */
public class ListViewModel extends ViewModel {
    private ListImgDataFetcher dataFetcher;

    /**
     * 获取数据
     */
    public void loadListImage(ILoginImageListListener imageListListener) {
        Logger.i("loadListImage start");
        if (dataFetcher == null) {
            dataFetcher = new ListImgDataFetcher(imageListListener);
        }
        dataFetcher.loadData();
    }

    private IMemberCommonService getMemberService() {
        return ServiceFactory.getService(IMemberCommonService.class);
    }

    /**
     * 例子：获取会员data数据
     */
    public void postMemberDataFromNet() {
        IMemberCommonService memberCommonService = getMemberService();
        if (memberCommonService == null) {
            Logger.i("getMemberService ,mServiceHolder == null");
            return;
        }
        memberCommonService.queryDataFromNet();
    }

    public void observeMemberData(@NonNull LifecycleOwner owner, @NonNull Observer<? super TestBean> observer) {
        IMemberCommonService memberCommonService = getMemberService();
        if (memberCommonService == null) {
            Logger.i("getMemberService ,mServiceHolder == null");
            return;
        }
        memberCommonService.getMemberLiveData().observe(owner, observer);
    }
}
